<?php
$this->breadcrumbs = array(
    'Posts' => array('index'),
    $modelPost->post_id => array('view', 'id' => $modelPost->post_id),
    'Create',
);
?>
<div class="box">
    <header>
        <h5>Create Post</h5>
    </header>
    <div class="body">	


	<?php
	$form = $this->beginWidget('CActiveForm', array(
	    'htmlOptions' => array(
		'class' => 'form-horizontal',
		'enctype' => "multipart/form-data"
	)));
	?>
	<?php if ($form->errorSummary($modelPost)) { ?>
    	<div class='alert alert-danger'>
		<?php echo $form->errorSummary($modelPost); ?>
    	</div>
	<?php } ?>	
	<?php /*
	  <div class="control-group">
	  <label for="inputEmail" class="control-label">Select type of Post</label>
	  <div class="controls">
	  <select id='select-type'>
	  <?php
	  foreach (Posts::getListType() as $key => $value) {
	  if ($key !== '') {
	  if (isset($_GET['type']) && $key == $_GET['type']) {
	  echo '<option value="' . $key . '"  selected>' . $value . '</option>';
	  } else {
	  echo '<option value="' . $key . '">' . $value . '</option>';
	  }
	  }
	  }
	  ?>
	  </select>
	  </div>
	  </div>
	 */ ?>
	<div class="control-group">				
	    <label for="inputEmail" class="control-label">Title <span>*</span></label>
	    <div class="controls">
		<?php echo $form->textField($modelPost, 'title'); ?>
	    </div>
	</div>

	<div class="control-group">
	    <label class="control-label">Content <span>*</span></label>
	    <div class="controls">
		<?php echo $form->textArea($modelPost, 'content'); ?>
	    </div>
	</div>

	<div class="control-group">
	    <label class="control-label">Photo</label>
	    <div class="controls">
		<?php
		for ($i = 0; $i < 5; $i++) {
		    echo "<input type='file' name='photo[]' accept='image/*'><br>";
		}
		?>
	    </div>
	</div>

	<div class="control-group">
	    <label class="control-label">Audio</label>
	    <div class="controls">
		<input type='file' name='audio' accept='audio/*'>
	    </div>
	</div>

	<div class="control-group">
	    <label class="control-label">Video</label>
	    <div class="controls">
		<input type='file' name='video' accept='video/*'>
	    </div>
	</div>

	<div class="control-group">
	    <label class="control-label">Tag <span>*</span></label>
	    <div class="controls">
		<?php echo $form->textField($modelPost, 'tags'); ?>
	    </div>
	</div>

	<?php
	/*
	  if (isset($_GET['type']) && $_GET['type'] == Posts::TYPE_PHOTO) {
	  ?>
	  <div class="control-group">
	  <label class="control-label">Photo</label>
	  <div class="controls">
	  <div class="pull-left" style="margin-right:20px;">
	  <input type='file' accept='image/*' name='photo[]'/>
	  <input type='hidden' value="<?php echo Posts::TYPE_PHOTO ?>" name="Posts[post_type]"/>
	  </div>
	  </div>
	  </div>

	  <?php
	  }
	  ?>

	  <?php
	  if (isset($_GET['type']) && $_GET['type'] == Posts::TYPE_AUDIO) {
	  ?>
	  <div class="control-group">
	  <label class="control-label">Audio</label>
	  <div class="controls">
	  <div class="pull-left" style="margin-right:20px;">
	  <input type='file' accept='audio/*' name='audio'/>
	  <input type='hidden' value="<?php echo Posts::TYPE_AUDIO ?>" name="Posts[post_type]"/>
	  </div>
	  </div>
	  </div>

	  <?php
	  }
	  ?>

	  <?php
	  if (isset($_GET['type']) && $_GET['type'] == Posts::TYPE_VIDEO) {
	  ?>
	  <div class="control-group">
	  <label class="control-label">Video</label>
	  <div class="controls">

	  <div class="pull-left" style="margin-right:20px;">
	  <input type='file' accept='video/*' name='video'/>
	  <input type='hidden' value="<?php echo Posts::TYPE_VIDEO ?>" name="Posts[post_type]"/>
	  </div>
	  </div>
	  </div>

	  <?php
	  }
	 * 
	 */
	?>



	<div class="control-group">
	    <div class="controls">    				
		<input type="submit" class="btn btn-large btn-info" value="Update" name='submit'/>
	    </div>
	</div>

	<?php
	$this->endWidget();
	?>


    </div>
</div>
<script>
    $(document).ready(function() {
	$('#select-type').change(function() {
	    var type = $(this).val();
	    window.location.assign("<?php echo BACKEND_SITE_URL ?>post/create?type=" + type);
	});
    });
</script>